//
//  ToBeSurePeiTongDetailViewController.m
//  MyProject
//
//  Created by Pei on 16/8/5.
//  Copyright © 2016年 Xiaobo Pei. All rights reserved.
//

#import "ToBeSurePeiTongDetailViewController.h"

#import "HTHorizontalSelectionList.h"
#import "ScanViewController.h"
//#import "SelectProjectViewController.h"
#import "SelectCheckTypeViewController.h"
#import "SelectCheckItemViewController.h"
#import "SelectModel.h"
//#import "CheckItemCell.h"
#import "CheckDetailViewController.h"
#import "UserInfo.h"
#import "ToBeSureCheckItemCell.h"
#import "ToBeSureTaskItemDetailVC.h"
#import "SelectZGPersonViewController.h"

@interface ToBeSurePeiTongDetailViewController ()<HTHorizontalSelectionListDelegate, HTHorizontalSelectionListDataSource, UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate, SelectCheckTypeViewControllerDelegate, ScanViewControllerDelegate, SelectCheckItemViewControllerDelegate,CheckDetailViewControllerDelegate, UIGestureRecognizerDelegate, SelectZGPersonViewControllerDelegate>
{
    HTHorizontalSelectionList *_segementView;
    
    UITableView *_myTable;
    UITableView *_secondMyTable;
    
    NSArray *_titleArray;
    
    UIView *_footView;
    
    NSDictionary *_checkDic;
    
    UIDatePicker *_datePicker;
    UIView *_dateTopView;
    
    NSString *_dateStr;
    
    UILabel *_detailLbl;
    
    UILabel *_detailLbl2;
    
    UILabel *_detailLbl3;
    
    UILabel *_detailLbl4;
    
    NSArray *_secondData;
    
    NSString *_InspectionNoStr;
    
    UITextField *_remarkField;
    
    NSDictionary *_InspectOrgAndProjectDic;
    
    NSDictionary *_currentDic;
    
    NSString *_currentStr;
    
    NSDictionary *ZGPersonDic;
    
    NSDictionary *firstDic;
}

@end

@implementation ToBeSurePeiTongDetailViewController

- (id)initWithDic:(NSDictionary*)dic{
    self = [super init];
    if (self) {
        [self getData:[[dic valueForKey:@"InspectionID"] intValue]];
        firstDic = dic;
    }
    return self;
}

- (void)getData:(int)id
{
    //Get_ToBeSure_Task_Detail
    [[YMNetLib getInstance] connectWithAction:Get_ToBeSure_Task_Detail method:@"GET" withContent:[NSString stringWithFormat:@"InspectionID=%d",id] withBody:nil withDelegate:self];
    _currentStr = Get_ToBeSure_Task_Detail;
}

- (void)NetDoOverSuccess:(NSDictionary*)body
{
    if ([_currentStr isEqualToString:Get_ToBeSure_Task_Detail]) {
        if ([[YMNetDataUtil getSuccessState:body] intValue] == 1)
        {
            _currentDic = body;
            
            _secondData = [_currentDic valueForKey:@"InspectItemList"];
            
            //_contentArray = [_currentDic valueForKey:@"InspectionList"];
            //[_myTable reloadData];
            
            [self initSelectView];
            [self initTable];
            [self initFootView];
            
            [self initSecondMyTableView];
            
            
            NSArray *tempArray = [[NSUserDefaults standardUserDefaults] objectForKey:Check_Type_Items];
            if (tempArray != nil && tempArray.count > 0) {
                
            }else{
                [self getCheckData];
            }
            
            
            NSArray *arrayT = [[NSUserDefaults standardUserDefaults] objectForKey:select_RiskLevel];
            if (arrayT != nil && arrayT.count > 0) {
            }else{
                [self getLevelData];
            }
            
        }
    }else if ([_currentStr isEqualToString:@"Check_Type_Items"]){
        if ([[YMNetDataUtil getSuccessState:body] intValue] == 1)
        {
            [[NSUserDefaults standardUserDefaults] setObject:[body valueForKey:@"DicList"] forKey:Check_Type_Items];
            [_myTable reloadData];
        }
        
    }else if ([_currentStr isEqualToString:@"select_RiskLevel"]){
        {
            [[NSUserDefaults standardUserDefaults] setObject:[body valueForKey:@"DicList"] forKey:select_RiskLevel];
            [_secondMyTable reloadData];
        }
        
    }else{
        if ([[YMNetDataUtil getSuccessState:body] intValue] == 1)
        {
            if ([self.delegate respondsToSelector:@selector(refreshSecondData)]) {
                [self.delegate refreshSecondData];
                [self.navigationController popViewControllerAnimated:YES];
            }
            
        }
    }
}


- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    [[NSNotificationCenter defaultCenter] postNotificationName:Hide_TabBar_Notification object:nil];
}

- (void)viewDidLoad {
    self.navTitle = @"检查单信息";
    [super viewDidLoad];
    
 
    
    UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 22)];
    [rightBtn setTitle:@"确认" forState:UIControlStateNormal];
    [rightBtn setTitleColor:kBlueColor forState:UIControlStateNormal];
    rightBtn.titleLabel.font = kAppFont(Home_Big_Size);
    [rightBtn addTarget:self action:@selector(rightBtnAcion) forControlEvents:UIControlEventTouchUpInside];
    [self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:rightBtn]];
    
    _titleArray = @[@"检查单信息", @"检查项"];
    
    
}

-(BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer shouldReceiveTouch:(UITouch*)touch {
    
    if([NSStringFromClass([touch.view class]) isEqual:@"UIControl"]){
        
        return NO;
        
    }
    
    if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
        //返回为NO则屏蔽手势事件
        return NO;
    }
    
    return YES;
    
    
    
}



- (void)getLevelData{
    [[YMNetLib getInstance] connectWithAction:Dictionary_Type_API method:@"GET" withContent:@"DicType=RiskLevel" withBody:nil withDelegate:self];
    _currentStr = @"select_RiskLevel";
}

- (void)getCheckData{
    [[YMNetLib getInstance] connectWithAction:Dictionary_Type_API method:@"GET" withContent:@"DicType=InspectType" withBody:nil withDelegate:self];
    _currentStr = @"Check_Type_Items";
}

#pragma mark ********************** UI **************************
- (void)initSelectView{
    _segementView = [[HTHorizontalSelectionList alloc] initWithFrame:CGRectMake(0.0f, 0.0f, kDeviceWidth, 40.0f)];
    _segementView.delegate = self;
    _segementView.dataSource = self;
    _segementView.autoFillWidth = YES;
    _segementView.font = 14;
    _segementView.sideMargin = 0;
    _segementView.isAdjustBottomLine = YES;
    _segementView.bottomLineMargin = 10.f;
    _segementView.selectionIndicatorColor = kBlueColor;
    [_segementView setSelectedButtonIndex:0];
    [_segementView setTitleColor:kGreenColor forState:UIControlStateNormal];
    [_segementView setBottomTrimColor:kGreenColor];
    [self.view addSubview:_segementView];
    
}

- (void)initSecondMyTableView{
    _secondMyTable = [[UITableView alloc] init];
    _secondMyTable.frame = CGRectMake(0.0f, _segementView.bottom, kDeviceWidth, kDeviceHeight-NAV_HEIGHT-_segementView.height);
    _secondMyTable.delegate = self;
    _secondMyTable.dataSource = self;
    _secondMyTable.backgroundColor = kRGB(241, 246, 250);
    _secondMyTable.tag = 119;
    [self.view addSubview:_secondMyTable];
    
    _secondMyTable.tableFooterView = [UIView new];
}

- (void)initTable{
    _myTable = [[UITableView alloc] init];
    _myTable.frame = CGRectMake(0.0f, _segementView.bottom, kDeviceWidth, kDeviceHeight-NAV_HEIGHT-_segementView.height);
    _myTable.delegate = self;
    _myTable.dataSource = self;
    _myTable.backgroundColor = kRGB(241, 246, 250);
    _myTable.tag = 116;
    [self.view addSubview:_myTable];
}
- (void)initFootView{
    _footView = [[UIView alloc] init];
    _footView.frame = CGRectMake(0.0f, 0.0f, kDeviceWidth, 54*5+40);
    _footView.backgroundColor = kWhiteColor;
    _myTable.tableFooterView = _footView;
    
    UIControl *companyControl = [[UIControl alloc] init];
    companyControl.frame = CGRectMake(0.0f, 0.0f, kDeviceWidth, 54.0f);
    [_footView addSubview:companyControl];
    
    UIImageView *arrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"02jiantou-"]];
    arrowImageView.frame = CGRectMake(kDeviceWidth-60.0f-10.0f/2.0f, (companyControl.height-19.0f/2.0f)/2.0f, 10.0f/2.0f, 19.0f/2.0f);
    //[companyControl addSubview:arrowImageView];
    
    UILabel *titleLbl = [[UILabel alloc] initWithFrame:CGRectMake(16.0f, (companyControl.height-(Home_Small_Size+2.0f))/2.0f, 60.0f, Home_Small_Size+2.0f)];
    titleLbl.textColor = kRGB(205, 206, 207);
    titleLbl.text = @"检查公司";
    titleLbl.font = kAppFont(Home_Small_Size+2.0f);
    [companyControl addSubview:titleLbl];
    
    _detailLbl = [[UILabel alloc] initWithFrame:CGRectMake(titleLbl.right, (companyControl.height-(Home_Small_Size))/2.0f, kDeviceWidth-16.0f-titleLbl.width-20.0f, Home_Small_Size)];
    _detailLbl.textColor = kRGB(100, 99, 104);
    _detailLbl.text = [_currentDic valueForKey:@"InspectOrgName"];
    _detailLbl.font = kAppFont(Home_Small_Size);
    _detailLbl.textAlignment = NSTextAlignmentRight;
    [companyControl addSubview:_detailLbl];
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(16.0f, companyControl.height-0.5f, kDeviceWidth-16.0f, 0.5f)];
    lineView.backgroundColor = kGreenColor;
    [companyControl addSubview:lineView];
    
    UIControl *projectControl = [[UIControl alloc] init];
    projectControl.frame = CGRectMake(0.0f, companyControl.bottom, kDeviceWidth, 54.0f);
    [projectControl addTarget:self action:@selector(projectControlAction) forControlEvents:UIControlEventTouchUpInside];
    [_footView addSubview:projectControl];
    
    UIImageView *arrowImageView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"02jiantou-"]];
    arrowImageView2.frame = CGRectMake(kDeviceWidth-60.0f-10.0f/2.0f, (projectControl.height-19.0f/2.0f)/2.0f, 10.0f/2.0f, 19.0f/2.0f);
    //[projectControl addSubview:arrowImageView2];
    
    UILabel *titleLbl2 = [[UILabel alloc] initWithFrame:CGRectMake(16.0f, (projectControl.height-(Home_Small_Size+2.0f))/2.0f, 60.0f, Home_Small_Size+2.0f)];
    titleLbl2.textColor = kRGB(205, 206, 207);
    titleLbl2.text = @"检查项目";
    titleLbl2.font = kAppFont(Home_Small_Size+2.0f);
    [projectControl addSubview:titleLbl2];
    
    _detailLbl2 = [[UILabel alloc] initWithFrame:CGRectMake(titleLbl2.right, (projectControl.height-(Home_Small_Size))/2.0f, kDeviceWidth-16.0f-titleLbl2.width-20.0f, Home_Small_Size)];
    _detailLbl2.textColor = kRGB(100, 99, 104);
    _detailLbl2.text = [_currentDic valueForKey:@"InspectProjectName"];
    _detailLbl2.font = kAppFont(Home_Small_Size);
    _detailLbl2.textAlignment = NSTextAlignmentRight;
    [projectControl addSubview:_detailLbl2];
    
    UIView *lineView2 = [[UIView alloc] initWithFrame:CGRectMake(16.0f, projectControl.height-0.5f, kDeviceWidth-16.0f, 0.5f)];
    lineView2.backgroundColor = kGreenColor;
    [projectControl addSubview:lineView2];
    
    UIControl *personControl = [[UIControl alloc] init];
    personControl.frame = CGRectMake(0.0f, projectControl.bottom, kDeviceWidth, 54.0f);
    [personControl addTarget:self action:@selector(projectControlAction) forControlEvents:UIControlEventTouchUpInside];
    [_footView addSubview:personControl];
    
    
    UILabel *titleLbl3 = [[UILabel alloc] initWithFrame:CGRectMake(16.0f, (personControl.height-(Home_Small_Size+2.0f))/2.0f, 60.0f, Home_Small_Size+2.0f)];
    titleLbl3.textColor = kRGB(205, 206, 207);
    titleLbl3.text = @"检查人";
    titleLbl3.font = kAppFont(Home_Small_Size+2.0f);
    [personControl addSubview:titleLbl3];
    
    _detailLbl3 = [[UILabel alloc] initWithFrame:CGRectMake(titleLbl3.right, (personControl.height-(Home_Small_Size))/2.0f, kDeviceWidth-16.0f-titleLbl3.width-20.0f, Home_Small_Size)];
    _detailLbl3.textColor = kRGB(100, 99, 104);
    _detailLbl3.text = [_currentDic valueForKey:@"Inspector"];
    _detailLbl3.font = kAppFont(Home_Small_Size);
    _detailLbl3.textAlignment = NSTextAlignmentRight;
    [personControl addSubview:_detailLbl3];
    
    UIView *lineView21 = [[UIView alloc] initWithFrame:CGRectMake(16.0f, personControl.height-0.5f, kDeviceWidth-16.0f, 0.5f)];
    lineView21.backgroundColor = kGreenColor;
    [personControl addSubview:lineView21];
    
    
    
    UIControl *ZGPersonControl = [[UIControl alloc] init];
    ZGPersonControl.frame = CGRectMake(0.0f, personControl.bottom, kDeviceWidth, 54.0f);
    //[ZGPersonControl addTarget:self action:@selector(ZGPersonControlAction) forControlEvents:UIControlEventTouchUpInside];
    [_footView addSubview:ZGPersonControl];
    
    
    UILabel *titleLbl4 = [[UILabel alloc] initWithFrame:CGRectMake(16.0f, (ZGPersonControl.height-(Home_Small_Size+2.0f))/2.0f, 80.0f, Home_Small_Size+2.0f)];
    titleLbl4.textColor = kRGB(205, 206, 207);
    titleLbl4.text = @"陪同检查人";
    titleLbl4.font = kAppFont(Home_Small_Size+2.0f);
    [ZGPersonControl addSubview:titleLbl4];
    
    _detailLbl4 = [[UILabel alloc] initWithFrame:CGRectMake(titleLbl4.right, (ZGPersonControl.height-(Home_Small_Size))/2.0f, kDeviceWidth-16.0f-titleLbl4.width-20.0f, Home_Small_Size)];
    _detailLbl4.textColor = kRGB(100, 99, 104);
    _detailLbl4.text = [_currentDic valueForKey:@"AccompanyPersons"];
    _detailLbl4.font = kAppFont(Home_Small_Size);
    _detailLbl4.textAlignment = NSTextAlignmentRight;
    [ZGPersonControl addSubview:_detailLbl4];
    
    UIImageView *arrowImageView4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"02jiantou-"]];
    arrowImageView4.frame = CGRectMake(kDeviceWidth-10.0f-10.0f/2.0f, (ZGPersonControl.height-19.0f/2.0f)/2.0f, 10.0f/2.0f, 19.0f/2.0f);
    //[ZGPersonControl addSubview:arrowImageView4];
    
    UIView *lineView22 = [[UIView alloc] initWithFrame:CGRectMake(16.0f, ZGPersonControl.height-0.5f, kDeviceWidth-16.0f, 0.5f)];
    lineView22.backgroundColor = kGreenColor;
    [ZGPersonControl addSubview:lineView22];

    
    
    UILabel *remarkLbl = [[UILabel alloc] initWithFrame:CGRectMake(16.0f, ZGPersonControl.bottom+10.0f, 46.0f, Home_Small_Size+2.0f)];
    remarkLbl.textColor = kRGB(205, 206, 207);
    remarkLbl.text = @"备注：";
    remarkLbl.font = kAppFont(Home_Small_Size+2.0f);
    [_footView addSubview:remarkLbl];
    
    _remarkField = [[UITextField alloc] init];
    _remarkField.frame = CGRectMake(remarkLbl.right+5.0f, remarkLbl.origin.y, kDeviceWidth-16.0f*2.0f-remarkLbl.width, 74.0f);
    _remarkField.attributedPlaceholder =[[NSAttributedString alloc] initWithString:@"再次输入需要备注的内容，不超过100字" attributes:@{NSForegroundColorAttributeName: kGreenColor, NSFontAttributeName : kAppFont(Home_Small_Size)}];
    _remarkField.font = kAppFont(Home_Small_Size);
    _remarkField.delegate = self;
    _remarkField.text = [_currentDic valueForKey:@"InspectRemark"];
    _remarkField.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;
    [_footView addSubview:_remarkField];
    
//    UIView *lineView3 = [[UIView alloc] initWithFrame:CGRectMake(0.0f, ZGPersonControl.bottom+40.0f+54.0f-0.5f, kDeviceWidth, 0.5f)];
//    lineView3.backgroundColor = kGreenColor;
//    [_footView addSubview:lineView3];
    
    
    UIView *lineView4 = [[UIView alloc] initWithFrame:CGRectMake(0.0f, _footView.height-0.5f, kDeviceWidth, 0.5f)];
    lineView4.backgroundColor = kGreenColor;
    [_footView addSubview:lineView4];
    
//    UIControl *ZGPersonControl = [[UIControl alloc] init];
//    ZGPersonControl.frame = CGRectMake(0.0f, lineView3.bottom, kDeviceWidth, 54.0f);
//    [ZGPersonControl addTarget:self action:@selector(ZGPersonControlAction) forControlEvents:UIControlEventTouchUpInside];
//    [_footView addSubview:ZGPersonControl];
//    
//    
//    UILabel *titleLbl4 = [[UILabel alloc] initWithFrame:CGRectMake(16.0f, (ZGPersonControl.height-(Home_Small_Size+2.0f))/2.0f, 60.0f, Home_Small_Size+2.0f)];
//    titleLbl4.textColor = kRGB(205, 206, 207);
//    titleLbl4.text = @"整改人";
//    titleLbl4.font = kAppFont(Home_Small_Size+2.0f);
//    [ZGPersonControl addSubview:titleLbl4];
//    
//    _detailLbl4 = [[UILabel alloc] initWithFrame:CGRectMake(titleLbl4.right, (ZGPersonControl.height-(Home_Small_Size))/2.0f, kDeviceWidth-16.0f-titleLbl4.width-20.0f-10.0f/2.0f-10.0f, Home_Small_Size)];
//    _detailLbl4.textColor = kRGB(100, 99, 104);
//    //_detailLbl4.text = [ZGPersonDic valueForKey:@"UserName"];
//    _detailLbl4.font = kAppFont(Home_Small_Size);
//    _detailLbl4.textAlignment = NSTextAlignmentRight;
//    [ZGPersonControl addSubview:_detailLbl4];
//    
//    UIImageView *arrowImageView4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"02jiantou-"]];
//    arrowImageView4.frame = CGRectMake(kDeviceWidth-10.0f-10.0f/2.0f, (ZGPersonControl.height-19.0f/2.0f)/2.0f, 10.0f/2.0f, 19.0f/2.0f);
//    [ZGPersonControl addSubview:arrowImageView4];
//    
//    UIView *lineView4 = [[UIView alloc] initWithFrame:CGRectMake(0.0f, _footView.height-0.5f, kDeviceWidth, 0.5f)];
//    lineView4.backgroundColor = kGreenColor;
//    [_footView addSubview:lineView4];
    
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    return NO;
}

#pragma mark ********************** Action *******************************
- (void)ZGPersonControlAction{
    NSLog(@"ZGPersonControlActionZGPersonControlActionZGPersonControlActionZGPersonControlAction");
    SelectZGPersonViewController *personVC = [[SelectZGPersonViewController alloc] init];
    personVC.delegate = self;
    [self.navigationController pushViewController:personVC animated:YES];
}

- (void)passSelectZGPerson:(NSDictionary *)tempDic{
    ZGPersonDic = tempDic;
    _detailLbl4.text = [ZGPersonDic valueForKey:@"UserName"];
    [_myTable reloadData];
}

- (void)rightBtnAcion
{
    //Sure_ConfirmAccompany
    [[YMNetLib getInstance] connectWithAction:Sure_ConfirmAccompany method:@"GET" withContent:[NSString stringWithFormat:@"AccompanyID=%d", [[firstDic valueForKey:@"AccompanyID"] intValue]] withBody:nil withDelegate:self];
    _currentStr = Sure_ConfirmAccompany;
    
}

- (void)scanBtnAction{
    ScanViewController *scanVC = [[ScanViewController  alloc] init];
    scanVC.delegate = self;
    [self.navigationController pushViewController:scanVC animated:YES];
}

- (void)projectControlAction
{
    //SelectProjectViewController *selectVC = [[SelectProjectViewController alloc] init];
    //selectVC.navTitle = @"选择检查项";
    //[self.navigationController pushViewController:selectVC animated:YES];
}

- (void)sureBtnAcion
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    // 格式化日期格式
    formatter. dateFormat = @"yyyy-MM-dd HH:mm:ss" ;
    _dateStr = [formatter stringFromDate:_datePicker.date];
    NSLog(@"=====%@", _dateStr);
    
    
    [_datePicker removeFromSuperview];
    _datePicker = nil;
    [_dateTopView removeFromSuperview];
    _dateTopView = nil;
    
    [_myTable reloadData];
}

- (void)cancleBtnAcion
{
    [_datePicker removeFromSuperview];
    _datePicker = nil;
    [_dateTopView removeFromSuperview];
    _dateTopView = nil;
}

#pragma mark ********************** Delegate ***************************
#pragma mark  ************************* UITableViewDataSource **************************************
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView.tag == 116) {
        return 3;
    }else{
        return _secondData.count;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.tag == 116) {
        static NSString *identifier = @"cell_house_History";
        UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell == nil)
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
        }
        cell.textLabel.textColor = kRGB(205, 206, 207);
        cell.textLabel.font = kAppFont(Home_Small_Size+2);
        cell.detailTextLabel.font = kAppFont(Home_Small_Size);
        cell.detailTextLabel.textColor = kRGB(100, 99, 104);
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        switch (indexPath.row) {
            case 0:
            {
                cell.accessoryType = UITableViewCellAccessoryNone;
                cell.textLabel.text = @"检查单号";
                //JDC +yyyyMMddHHmmssSSS
                //NSDateFormatter *formatter =[[NSDateFormatter alloc] init];
                //[formatter setDateFormat:@"yyyyMMddHHmmssSSS"];
                //NSString *currentTime = [formatter stringFromDate:[NSDate date]];
                cell.detailTextLabel.text = [_currentDic valueForKey:@"InspectionName"];
                //_InspectionNoStr = [NSString stringWithFormat:@"JDC%@", currentTime];
            }
                break;
            case 1:
            {
                cell.accessoryType = UITableViewCellAccessoryNone;
                cell.textLabel.text = @"检查类型";
                NSArray *tempArray = [[NSUserDefaults standardUserDefaults] objectForKey:Check_Type_Items];
                for (NSDictionary *hhh in tempArray) {
                    if ([[hhh valueForKey:@"Value"] intValue] == [[_currentDic valueForKey:@"InspectType"] intValue]) {
                        cell.detailTextLabel.text = [hhh valueForKey:@"Name"];
                    }
                }
                
                
                
                
                UIImageView *arrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"02jiantou-"]];
                arrowImageView.frame = CGRectMake(kDeviceWidth-16.0f-10.0f/2.0f, (54.0f-19.0f/2.0f)/2.0f, 10.0f/2.0f, 19.0f/2.0f);
                
                cell.accessoryView = arrowImageView;
            }
                break;
            case 2:
            {
                cell.accessoryType = UITableViewCellAccessoryNone;
                cell.textLabel.text = @"检查日期";
                NSString *dateS = [_currentDic valueForKey:@"InspectDate"];
                dateS = [dateS stringByReplacingOccurrencesOfString:@"T" withString:@" "];
                cell.detailTextLabel.text = dateS;//[_currentDic valueForKey:@"InspectDate"];
                
                UIImageView *arrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"02jiantou-"]];
                arrowImageView.frame = CGRectMake(kDeviceWidth-16.0f-10.0f/2.0f, (54.0f-19.0f/2.0f)/2.0f, 10.0f/2.0f, 19.0f/2.0f);
                
                cell.accessoryView = arrowImageView;
                
                UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(16.0f, 53.5f, kDeviceWidth-16.0f, 0.5f)];
                lineView.backgroundColor = kGreenColor;
                [cell addSubview:lineView];
            }
                break;
            default:
                break;
        }
        return cell;
    }else{
        static NSString *identifier = @"ToBeSureCheckItemCell";
        ToBeSureCheckItemCell *cell = (ToBeSureCheckItemCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell == nil)
        {
            cell = [[ToBeSureCheckItemCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        NSDictionary *ddd = [_secondData objectAtIndex:indexPath.row];
        [cell showWithData:ddd];
        return cell;
    }
    return nil;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.tag == 116) {
        return 54.0f;
    }else{
        return 80.0f;
    }
    return 0.0f;
}


#pragma mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.tag == 116) {
        switch (indexPath.row) {
            case 1:
            {
                //SelectCheckTypeViewController *checkVC = [[SelectCheckTypeViewController alloc] init];
                //checkVC.delegate = self;
                //[self.navigationController pushViewController:checkVC animated:YES];
            }
                break;
            case 2:
            {
                /*
                 [_datePicker removeFromSuperview];
                 _datePicker = nil;
                 _datePicker = [[UIDatePicker alloc] init];
                 _datePicker.datePickerMode = UIDatePickerModeDateAndTime;
                 _datePicker.minimumDate = [NSDate date];
                 _datePicker.frame = CGRectMake(0.0f, self.view.height-200.0f, kDeviceWidth, 200.0f);
                 _datePicker.backgroundColor = kDefaultBackgroundColor;
                 [self.view addSubview:_datePicker];
                 
                 [_dateTopView removeFromSuperview];
                 _dateTopView = nil;
                 _dateTopView = [[UIView alloc] init];
                 _dateTopView.backgroundColor = kWhiteColor;
                 _dateTopView.frame = CGRectMake(-0.5f, self.view.height-_datePicker.height-40.0f, kDeviceWidth+1.0f, 40.0f);
                 _dateTopView.layer.borderColor = kGreenColor.CGColor;
                 _dateTopView.layer.borderWidth = 0.5f;
                 [self.view addSubview:_dateTopView];
                 
                 UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
                 [sureBtn setTitle:@"确认" forState:UIControlStateNormal];
                 [sureBtn setTitleColor:kBlueColor forState:UIControlStateNormal];
                 sureBtn.titleLabel.font = kAppFont(Home_Big_Size);
                 sureBtn.frame = CGRectMake(kDeviceWidth-40.0f-16.0f, (40-Home_Big_Size)/2.0f, 40.0f, Home_Big_Size);
                 [sureBtn addTarget:self action:@selector(sureBtnAcion) forControlEvents:UIControlEventTouchUpInside];
                 [_dateTopView addSubview:sureBtn];
                 
                 UIButton *cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
                 [cancleBtn setTitle:@"取消" forState:UIControlStateNormal];
                 [cancleBtn setTitleColor:kBlueColor forState:UIControlStateNormal];
                 cancleBtn.titleLabel.font = kAppFont(Home_Big_Size);
                 cancleBtn.frame = CGRectMake(16.0f, (40-Home_Big_Size)/2.0f, 40.0f, Home_Big_Size);
                 [cancleBtn addTarget:self action:@selector(cancleBtnAcion) forControlEvents:UIControlEventTouchUpInside];
                 [_dateTopView addSubview:cancleBtn];
                 */
            }
                break;
            default:
                break;
        }
    }else{
        NSDictionary *ddd = [_secondData objectAtIndex:indexPath.row];
        ToBeSureTaskItemDetailVC *checkDetailVC = [[ToBeSureTaskItemDetailVC alloc] initWithDic:ddd];
        [self.navigationController pushViewController:checkDetailVC animated:YES];
    }
    
}

#pragma mark - HTHorizontalSelectionList delegate
- (NSInteger)numberOfItemsInSelectionList:(HTHorizontalSelectionList *)selectionList
{
    return _titleArray.count;
}

- (NSString *)selectionList:(HTHorizontalSelectionList *)selectionList titleForItemWithIndex:(NSInteger)index
{
    return _titleArray[index];
}

- (void)selectionList:(HTHorizontalSelectionList *)selectionList didSelectButtonWithIndex:(NSInteger)index
{
    switch (index) {
        case 0:
        {
            [_secondMyTable removeFromSuperview];
            [self.view addSubview:_myTable];
        }
            break;
        case 1:
        {
            [_myTable removeFromSuperview];
            [self.view addSubview:_secondMyTable];
            
            //SelectCheckItemViewController *checkItemVC = [[SelectCheckItemViewController alloc] init];
            //checkItemVC.delegate = self;
            //[self.navigationController pushViewController:checkItemVC animated:YES];
        }
            break;
            
        default:
            break;
    }
}


- (void)deleteBtnAction:(UIButton*)sender
{
    SelectModel *selectModel = [_secondData objectAtIndex:sender.tag];
    NSMutableArray *tempArray = [[NSMutableArray alloc] initWithArray:_secondData];
    //    NSMutableArray *tempA = [[NSMutableArray alloc] initWithCapacity:3];
    //    for (SelectModel *tempM in tempArray) {
    //        if ([tempM isEqual:selectModel]) {
    //            [tempArray removeObject:tempM];
    //        }
    //    }
    
    for (int i=0; i<tempArray.count; i++) {
        SelectModel *tempModel1 = [tempArray objectAtIndex:sender.tag];
        if (selectModel.InspectContentID == tempModel1.InspectContentID) {
            [tempArray removeObject:tempModel1];
        }
    }
    
    _secondData = tempArray;
    [_secondMyTable reloadData];
}

- (void)passSelectModel:(NSArray *)tempArray
{
    NSLog(@"++++++++++++");
    _secondData = tempArray;
    [_secondMyTable reloadData];
}

- (void)passScanValue:(NSDictionary *)tempDic
{
    _InspectOrgAndProjectDic = tempDic;
    
    _detailLbl.text = [tempDic valueForKey:@"unitName"];
    _detailLbl2.text = [tempDic valueForKey:@"projectName"];
}

- (void)passSelectCheckType:(NSDictionary *)tempDic
{
    NSLog(@"+++++++++++++++%@", [tempDic description]);
    _checkDic = tempDic;
    [_myTable reloadData];
}

- (void)passModel:(SelectModel *)model
{
    NSMutableArray *tempSecondArray = [[NSMutableArray alloc] initWithArray:_secondData];
    
    for (int i = 0; i < _secondData.count; i ++) {
        SelectModel *selectModel = [_secondData objectAtIndex:i];
        if (selectModel.InspectContentID == model.InspectContentID) {
            [tempSecondArray replaceObjectAtIndex:i withObject:model];
        }
    }
    
    _secondData = tempSecondArray;
}

@end
